<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 
        Vue2 中  v-model
            :value @input

       -->

      <base-checkbox label="勾选" v-model="isChecked"></base-checkbox>
    </div>

    <script src="./lib/vue.js"></script>
    <script>
      Vue.component("base-checkbox", {
        template: `
          <div class="base-checkbox">
            <input type="checkbox" :checked="value" @change="fn1" /> 
            <span>{{ label }}</span>
          </div>
        `,

        props: ["label", "value"],

        methods: {
          fn1(event) {
            console.log("fn1");
            this.$emit("input", event.target.checked);
          },
        },

        mounted() {
          console.log(this);
        },
      });

      new Vue({
        el: "#app",
        data() {
          return {
            isChecked: true,
          };
        },
        methods: {
          onChange(event) {
            console.log("onChange", event);
          },
        },
      });
    </script>
  </body>
</html>
